import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["intervalTypeList", "statusList"];

/**
 * model 并发管理器/请求定义（并发程序）
 * @date: 2018-9-10


 */
import { getResponse, createPagination } from 'utils/utils';
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { fetchRequestList as _fetchRequestList, createRequest as _createRequest, fetchRequestDetail as _fetchRequestDetail, fetchParams as _fetchParams, deleteJobInfo as _deleteJobInfo, pauseJobInfo as _pauseJobInfo, resumeJobInfo as _resumeJobInfo, triggerJobInfo as _triggerJobInfo, stopJob as _stopJob, fetchJobLog as _fetchJobLog, fetchJobLogError as _fetchJobLogError, deleteJobLog as _deleteJobLog, fetchProgress as _fetchProgress } from "../services/concRequestService";
export default {
  namespace: 'concRequest',
  state: {
    list: [],
    // 数据列表
    pagination: {},
    // 分页器
    concRequestDetail: {},
    // 详情数据
    paramList: [],
    // 请求参数
    modalVisible: false,
    // 新增请求模态框
    concurrentVisible: false,
    // 请求ID模态框
    logMsgVisible: false,
    // 日志信息模态框
    intervalTypeList: [],
    // 间隔类型
    statusList: [],
    // 状态
    jobLogList: [],
    // 调度日志列表
    jobPagination: {},
    // 调度日志分页
    jobErrorDetail: {},
    // 调度日志错误详情
    jobLogLdp: {} // 调度日志值集

  },
  effects: {
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_, _ref) {
      var call, put, res, intervalTypeList, statusList, jobLogLdp;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                jobResultList: 'CSDR.LOG.JOB_RESULT',
                clientResultList: 'CSDR.LOG.CLIENT_RESULT',
                intervalTypeList: 'CSDR.REQUEST.INTERVAL_TYPE',
                statusList: 'CSDR.JOB_STATUS'
              });

            case 4:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);
              intervalTypeList = res.intervalTypeList, statusList = res.statusList, jobLogLdp = _objectWithoutProperties(res, _excluded);

              if (!res) {
                _context.next = 10;
                break;
              }

              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  intervalTypeList: intervalTypeList,
                  statusList: statusList,
                  jobLogLdp: jobLogLdp
                }
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    fetchRequestList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRequestList(_ref2, _ref3) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchRequestList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.next = 4;
              return call(_fetchRequestList, payload);

            case 4:
              result = _context2.sent;
              result = getResponse(result);

              if (!result) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: result.content,
                  pagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchRequestList);
    }),
    // 创建
    createRequest: /*#__PURE__*/_regeneratorRuntime.mark(function createRequest(_ref4, _ref5) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createRequest$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call;
              _context3.next = 4;
              return call(_createRequest, payload);

            case 4:
              res = _context3.sent;
              return _context3.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, createRequest);
    }),
    // 查询job详情
    fetchRequestDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchRequestDetail(_ref6, _ref7) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchRequestDetail$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call, put = _ref7.put;
              _context4.next = 4;
              return call(_fetchRequestDetail, payload);

            case 4:
              res = _context4.sent;
              result = getResponse(res);

              if (!result) {
                _context4.next = 9;
                break;
              }

              _context4.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  concRequestDetail: result
                }
              });

            case 9:
              return _context4.abrupt("return", result);

            case 10:
            case "end":
              return _context4.stop();
          }
        }
      }, fetchRequestDetail);
    }),
    // 查询请求参数
    fetchParams: /*#__PURE__*/_regeneratorRuntime.mark(function fetchParams(_ref8, _ref9) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchParams$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call, put = _ref9.put;
              _context5.next = 4;
              return call(_fetchParams, payload);

            case 4:
              res = _context5.sent;
              result = getResponse(res);

              if (!result) {
                _context5.next = 9;
                break;
              }

              _context5.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  paramList: result
                }
              });

            case 9:
              return _context5.abrupt("return", result);

            case 10:
            case "end":
              return _context5.stop();
          }
        }
      }, fetchParams);
    }),
    // 查询调度日志
    fetchJobLog: /*#__PURE__*/_regeneratorRuntime.mark(function fetchJobLog(_ref10, _ref11) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchJobLog$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call, put = _ref11.put;
              _context6.next = 4;
              return call(_fetchJobLog, payload);

            case 4:
              res = _context6.sent;
              result = getResponse(res);

              if (!result) {
                _context6.next = 9;
                break;
              }

              _context6.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobLogList: result.content,
                  jobPagination: createPagination(result)
                }
              });

            case 9:
              return _context6.abrupt("return", result);

            case 10:
            case "end":
              return _context6.stop();
          }
        }
      }, fetchJobLog);
    }),
    // 查询调度日志错误详情
    fetchJobLogError: /*#__PURE__*/_regeneratorRuntime.mark(function fetchJobLogError(_ref12, _ref13) {
      var payload, call, put, res, result;
      return _regeneratorRuntime.wrap(function fetchJobLogError$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call, put = _ref13.put;
              _context7.next = 4;
              return call(_fetchJobLogError, payload);

            case 4:
              res = _context7.sent;
              result = getResponse(res);

              if (!result) {
                _context7.next = 9;
                break;
              }

              _context7.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  jobErrorDetail: result
                }
              });

            case 9:
              return _context7.abrupt("return", result);

            case 10:
            case "end":
              return _context7.stop();
          }
        }
      }, fetchJobLogError);
    }),
    // 删除调度日志
    deleteJobLog: /*#__PURE__*/_regeneratorRuntime.mark(function deleteJobLog(_ref14, _ref15) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteJobLog$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.next = 4;
              return call(_deleteJobLog, payload);

            case 4:
              res = _context8.sent;
              return _context8.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context8.stop();
          }
        }
      }, deleteJobLog);
    }),
    // 删除
    deleteJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function deleteJobInfo(_ref16, _ref17) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteJobInfo$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref16.payload;
              call = _ref17.call;
              _context9.next = 4;
              return call(_deleteJobInfo, payload);

            case 4:
              res = _context9.sent;
              return _context9.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context9.stop();
          }
        }
      }, deleteJobInfo);
    }),
    // 暂停
    pauseJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function pauseJobInfo(_ref18, _ref19) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function pauseJobInfo$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref18.payload;
              call = _ref19.call;
              _context10.next = 4;
              return call(_pauseJobInfo, payload);

            case 4:
              res = _context10.sent;
              return _context10.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context10.stop();
          }
        }
      }, pauseJobInfo);
    }),
    // 恢复
    resumeJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function resumeJobInfo(_ref20, _ref21) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function resumeJobInfo$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref20.payload;
              call = _ref21.call;
              _context11.next = 4;
              return call(_resumeJobInfo, payload);

            case 4:
              res = _context11.sent;
              return _context11.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, resumeJobInfo);
    }),
    // 执行
    triggerJobInfo: /*#__PURE__*/_regeneratorRuntime.mark(function triggerJobInfo(_ref22, _ref23) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function triggerJobInfo$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref22.payload;
              call = _ref23.call;
              _context12.next = 4;
              return call(_triggerJobInfo, payload);

            case 4:
              res = _context12.sent;
              return _context12.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context12.stop();
          }
        }
      }, triggerJobInfo);
    }),
    // 终止
    stopJob: /*#__PURE__*/_regeneratorRuntime.mark(function stopJob(_ref24, _ref25) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function stopJob$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref24.payload;
              call = _ref25.call;
              _context13.next = 4;
              return call(_stopJob, payload);

            case 4:
              res = _context13.sent;
              return _context13.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context13.stop();
          }
        }
      }, stopJob);
    }),
    // 获取任务进度
    fetchProgress: /*#__PURE__*/_regeneratorRuntime.mark(function fetchProgress(_ref26, _ref27) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function fetchProgress$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref26.payload;
              call = _ref27.call;
              _context14.next = 4;
              return call(_fetchProgress, payload);

            case 4:
              result = _context14.sent;
              return _context14.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context14.stop();
          }
        }
      }, fetchProgress);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref28) {
      var payload = _ref28.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};